<template>
  <div class="hm-detail">
    <van-nav-bar
      class="nav-bar"
      title="面经详情"
      left-text="返回"
      left-arrow
      fixed
      @click-left="$router.back()"
    />
    <div class="title">
      <h2>{{ list.stem }}</h2>
    </div>
    <div class="content">
      <span>{{ list.createdAt }}</span>
      <span> | </span>
      <span>{{ list.views }} 浏览量</span>
      <span> | </span>
      <span>{{ list.likeFlag }} 点赞数</span>
    </div>
    <div class="uesr">
      <img :src="list.avatar" alt="" />
      <span>{{ list.creator }}</span>
    </div>
    <div class="text" v-html="list.content"></div>
    <div class="collect" @click="collect(list.id)">收藏</div>
    <div class="like" @click="like(list.id)">点赞</div>
  </div>
</template>

<script>
import axios from "axios";
import Bus from "@/Bus";
export default {
  data() {
    return {
      id: "",
      list: {},
    };
  },
  created() {
    this.get(this.$route.params.id);
  },
  methods: {
    async get(id) {
      const res = await axios({
        url: "http://interview-api-t.itheima.net/h5/interview/show",
        params: { id: id },
        headers: { Authorization: `Bearer ${localStorage.getItem("token")}` },
      });
      this.list = res.data.data;
    },
    collect(id) {
      Bus.$emit("collect", id);
    },
    like(id) {
      this.$emit("like", id);
    },
  },
  activated() {
    this.get(this.$route.params.id);
  },
};
</script>

<style lang="less" scoped>
.like {
  width: 50px;
  height: 50px;
  border-radius: 50%;
  background-color: #ccc;
  position: fixed;
  right: 100px;
  bottom: 100px;
  text-align: center;
  line-height: 50px;
}
.collect {
  width: 50px;
  height: 50px;
  border-radius: 50%;
  background-color: #ccc;
  position: fixed;
  right: 30px;
  bottom: 100px;
  text-align: center;
  line-height: 50px;
}
.hm-detail {
  padding-top: 46px;
}

.content {
  font-size: 12px;
  color: #9fa19f;
}
.uesr {
  width: 100%;
  height: 60px;
  display: flex;
  align-items: center;
  img {
    width: 40px;
  }
}
</style>
